package com.yingside.io.io;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class TestObjectStream {
    public static void main(String[] args) {
        /*FileOutputStream fos = null;
        ObjectOutputStream oos = null;
        try {
            fos = new FileOutputStream("images/Student.sb");
            oos = new ObjectOutputStream(new BufferedOutputStream(fos));

            Student s1 = new Student(1,"徐益1","138888888881");
            Student s2 = new Student(2,"徐益2","138888888882");
            Student s3 = new Student(3,"徐益3","138888888883");
            Student s4 = new Student(4,"徐益4","138888888884");

            List<Student> list = new ArrayList<Student>();
            list.add(s1);
            list.add(s2);
            list.add(s3);
            list.add(s4);

            oos.writeObject(list);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                oos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }*/


        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(
                    new BufferedInputStream(
                            new FileInputStream(
                                    new File("images/Student.sb"))));

            List<Student> stus = (List<Student>)ois.readObject();

            System.out.println("stus = " + stus);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
